<?php
/**
 * object强制转换成array后，某些情况下无法用key直接获取数组数据的特性（比如数字key）
 * PHP手册有详细说明：
 * If an object is converted to an array, the result is an array whose elements are 
 * the object's properties. The keys are the member variable names, with a few 
 * notable exceptions: 
 *     integer properties are unaccessible; 
 *     private variables have the class name prepended to the variable name; 
 *     protected variables have a '*' prepended to the variable name. 
 * These prepended values have null bytes on either side. 
 * This can result in some unexpected behaviour
 * 
 * @link http://www.php.net/manual/en/language.types.array.php
 * @version $Id: can_not_read_from_key_if_object_conv_2_array.php 218 2012-10-08 08:00:27Z horseluke@126.com $
 */

$raiders_hotspots_cat = array ( '1000' => 'cat_1', '1001' => 'cat_2', '1002' => 'cat_3', '1003' => 'cat_4', '1004' => 'cat_5', );
$raiders_hotspots_cat = json_encode($raiders_hotspots_cat);
$raiders_hotspots_cat = (array)json_decode($raiders_hotspots_cat);    //留意这里，没有第二个参数true，然后强制转换为array

echo 'gettype:'. gettype($raiders_hotspots_cat);
echo "\r\n";
echo "=======================================";
echo "\r\n";


var_export($raiders_hotspots_cat);
echo "\r\n";
echo "=======================================";
echo "\r\n";

echo $raiders_hotspots_cat['1004'];    //Notice: Undefined index:  1004 in aaa.php on line 33
echo "\r\n";
echo "=======================================";
echo "\r\n";

foreach($raiders_hotspots_cat as $ddd => $xxxx){
	echo $raiders_hotspots_cat[$ddd];    //Notice: Undefined index:  ### in aaa.php on line 39
	echo "\r\n";
}